//
//设备信息
//
<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="left"><Breadcrumb /></div>
        <div class="right">
          <HeaderOperation :parent="this" />
        </div>
      </div>
    </div>
    <div v-loading="loading" class="main_main">
      <search-bar-new :parent="this" />
      <div ref="table_container" class="table_container">
        <el-table
          v-if="tableColumns.length>0"
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"
          style="width: 99.9%"
          row-key="id"
          :cell-style="cellStyle"
          @cell-click="cellClick"
          @sort-change="(column)=>{sortChange(column, this)}"
          @selection-change="(val)=>{selectionChange(val, this)}"
        >
          <el-table-column type="selection" :width="70" align="center" />

          <!--          <el-table-column-->
          <!--            label="设备配图"-->
          <!--            prop="picture"-->
          <!--            min-width="80"-->
          <!--          >-->
          <!--            <template slot-scope="scope">-->
          <!--              <el-image-->
          <!--                v-if="scope.row.avatarUrl"-->
          <!--                style="width: 35px; height: 35px"-->
          <!--                :src="scope.row.avatarUrl"-->
          <!--                :preview-src-list="[scope.row.avatarUrl]"-->
          <!--              />-->
          <!--              <div v-else style="width: 35px; height: 35px">-->
          <!--                <img :src="icon_notAvailable" class="icon_notAvailable">-->
          <!--              </div>-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <Column
            v-for="(column,index) in tableColumns"
            :key="index"
            :align="column.align"
            :prop="column.prop"
            :is-show="column.isShow"
            :label="column.label"
            :sortable="column.sortable"
            :width="column.width"
            :min-width="column.minWidth"
            :column-type="column.columnType"
          />
          <el-table-column
            label="附件"
            min-width="80"
          >
            <template slot-scope="scope">
              <FileManage
                :file-names="scope.row.fileName"
                :file-real-names="scope.row.fileRealName"
                :file-urls="scope.row.fileUrl"
                :readonly="true"
                class="accessory"
              />
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" fixed="right" width="120">
            <template slot-scope="scope">
              <el-button
                v-hasPermi="['device:baseStandingBook:edit']"
                type="text"
                @click.stop="edit(scope.row)"
              >编辑</el-button>
              <el-button
                v-hasPermi="['device:baseStandingBook:delete']"
                type="text"
                @click.stop="deleteOne(scope.row)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>

    <PrintEquipmentInfo_large ref="print" :print-data="printData_large" />
    <PrintEquipmentInfo_small ref="print" :print-data="printData_small" />
  </div>
</template>

<script>
import { list, remove, listType, importMethod, getInfo, deptList, typeList } from '@/api/equipmentManage/baseInfo/equipmentInfo'
import AddOrUpdate from './addOrUpdate'
import PrintEquipmentInfo_large from '@/components/print/PrintEquipmentInfo_large'
import PrintEquipmentInfo_small from '@/components/print/PrintEquipmentInfo_small'
import ShowDetailOld from '@/components/JLINK2/common/ShowDetailOld' // 查看页面
import icon_notAvailable from '@/assets/images/baseInfo/暂无图片.png'
export default {
  name: 'Index',
  components: { PrintEquipmentInfo_large, PrintEquipmentInfo_small }, // 组件注册
  data() {
    return {
      icon_notAvailable: icon_notAvailable,
      loading: true,
      pageId: '设备信息', // 页面唯一标识
      pageExportId: '设备信息导出', // 页面导出标识
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'code',
        isAsc: 'desc',
        status: '1'
      },
      typeData: {
        status: 1
      },
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'statusName', label: '状态', canOrder: false, isShow: false },
        { prop: 'avatarUrl', label: '设备配图', minWidth: '120', columnType: 'picture', canOrder: false },
        { prop: 'code', label: '设备编码', sortable: 'custom' },
        { prop: 'name', label: '设备名称', canOrder: false },
        { prop: 'typeName', label: '设备类型', canOrder: false },
        { prop: 'location', label: '设备位置', minWidth: '200', canOrder: false },
        { prop: 'model', label: '规格型号', minWidth: '200', canOrder: false },
        { prop: 'firmName', label: '设备厂商', canOrder: false },
        { prop: 'purchaseMoneyThousandths', label: '采购金额(元)', align: 'right' },
        { prop: 'purchaseTime', label: '购买日期', sortable: 'custom' },
        { prop: 'warrantyEndTime', label: '保修截止日期', sortable: 'custom' },
        { prop: 'deptName', label: '使用部门', canOrder: false },
        { prop: 'realName', label: '设备负责人', canOrder: false },
        { prop: 'machineNumber', label: '机台号', canOrder: false },
        // { prop: 'protoName', label: '通讯协议', canOrder: false },
        // { prop: 'ip', label: 'IP', canOrder: false },
        // { prop: 'port', label: '端口号', canOrder: false },
        { prop: 'remark', label: '备注', canOrder: false }
      ],
      exportTableColumns: [// 表格常规字段（初始值）
        { prop: 'code', label: '设备编码', sortable: 'custom' },
        { prop: 'name', label: '设备名称', canOrder: false },
        { prop: 'typeName', label: '设备类型', canOrder: false },
        { prop: 'location', label: '设备位置', minWidth: '200', canOrder: false },
        { prop: 'model', label: '规格型号', minWidth: '200', canOrder: false },
        { prop: 'firmName', label: '设备厂商', canOrder: false },
        { prop: 'purchaseMoney', label: '采购金额(元)', align: 'right' },
        { prop: 'purchaseTime', label: '购买日期', sortable: 'custom' },
        { prop: 'warrantyEndTime', label: '保修截止日期', sortable: 'custom' },
        { prop: 'deptName', label: '使用部门', canOrder: false },
        { prop: 'realName', label: '设备负责人', canOrder: false },
        { prop: 'machineNumber', label: '机台号', canOrder: false },
        // { prop: 'protoName', label: '通讯协议', canOrder: false },
        // { prop: 'ip', label: 'IP', canOrder: false },
        // { prop: 'port', label: '端口号', canOrder: false },
        { prop: 'remark', label: '备注', canOrder: false }
      ],
      defaultExport: [],
      defaultSearchColumns: [// 搜索区常规字段（初始值）
        { prop: 'searchValue', label: '模糊搜索', type: 'input' },
        // { prop: 'code', label: '设备编码', type: 'input' },
        // { prop: 'name', label: '设备名称', type: 'input' },
        { prop: 'typeId', label: '设备类型', type: 'select', optionsName: 'equipmentInfoOptions' },
        // { prop: 'model', label: '规格型号', type: 'input' },
        { prop: 'status', label: '状态', type: 'select', optionsName: 'statusOptions', isShow: false },
        // { prop: 'location', label: '设备位置', type: 'input' },
        // { prop: 'firmName', label: '设备厂商', type: 'input' },
        { prop: 'purchaseTime', label: '购买日期', type: 'time' },
        { prop: 'warrantyEndTime', label: '保修截止日期', type: 'time' },
        { prop: 'deptId', label: '使用部门', type: 'select', optionsName: 'deptName' }
        // { prop: 'realName', label: '设备负责人', type: 'input' },
        // { prop: 'machineNumber', label: '机台号', type: 'input' }
        // { prop: 'protoId', label: '通讯协议', type: 'select', optionsName: 'protoName' },
        // { prop: 'ip', label: 'IP', type: 'input' },
        // { prop: 'port', label: '端口号', type: 'input' }
      ],
      statusOptions: [ // 选择组件数据源
        { value: undefined, label: '全部' },
        { value: '1', label: '启用' },
        { value: '0', label: '停用' }
      ],
      operationData: [ // 右上角的操作按钮
        { label: '新增', perm: 'device:baseStandingBook:add' },
        { label: '导入', perm: 'device:baseStandingBook:import' },
        { label: '批量操作', perm: '' },
        { label: '批量删除', perm: 'device:baseStandingBook:delete' },
        { label: '批量导出3', perm: 'device:baseStandingBook:export' },
        { label: '打印', perm: 'equipmentManage:equipmentInfoz:list' },
        { label: '页面配置', perm: '' }
      ],

      equipmentInfoOptions: [],
      deptName: [],
      protoName: [],
      printData_large: [],
      printData_small: [],
      showKey: {
        type: 'column_two',
        keys: [
          { type: 'form', name: '设备编码', key: 'code' },
          { type: 'form', name: '设备名称', key: 'name' },
          { type: 'form', name: '设备类型', key: 'typeName' },
          { type: 'form', name: '设备位置', key: 'location' },
          { type: 'form', name: '规格型号', key: 'model' },
          { type: 'form', name: '设备厂商', key: 'firmName' },
          { type: 'form', name: '购买日期', key: 'purchaseTime' },
          { type: 'form', name: '采购金额(元)', key: 'purchaseMoneyThousandths' },
          { type: 'form', name: '保修截止日期', key: 'warrantyEndTime' },
          { type: 'form', name: '使用部门', key: 'deptName' },
          { type: 'form', name: '设备负责人', key: 'realName' },
          { type: 'form', name: '机台号', key: 'machineNumber' },
          // { type: 'form', name: '通讯协议', key: 'protoName' },
          // { type: 'form', name: 'IP', key: 'ip' },
          // { type: 'form', name: '端口号', key: 'port' },
          { type: 'file', name: '附件', fileName: 'fileName', fileRealName: 'fileRealName', fileUrl: 'fileUrl' },
          { type: 'form', name: '备注', key: 'remark', length: 'double' },
          { type: 'form', name: '状态', key: 'status' },
          { type: 'file', name: '设备配图', fileName: 'avatar', fileRealName: 'avatar', fileUrl: 'avatarUrl' }
        ]
      }
    }
  },
  created() {
    this.getListType()
    this.getdeptList()
    this.getprotoName()
    console.log(this.icon_notAvailable)
  },
  methods: {
    cellStyle({ row, column }) {
      if (column.property == 'code') {
        return {
          cursor: 'pointer',
          color: '#387bfc'
        }
      }
    },
    cellClick(row, column, cell) {
      switch (column.property) {
        case 'code':
          this.showDetail(row)
          break
      }
    },
    getList() {
      list(this.pageData).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
          this.tableHeight = this.$refs.table_container.offsetHeight
        })
      })
    },
    getExportData(data) {
      return list(data)
    },
    getdeptList() {
      deptList().then(res => {
        res.data.forEach(item => {
          this.deptName.push({
            value: item.deptId,
            label: item.deptName
          })
        })
      })
    },
    getprotoName() {
      typeList().then(res => {
        res.data.forEach(item => {
          this.protoName.push({
            value: item.id,
            label: item.name
          })
        })
      })
    },
    getListType() {
      listType().then(res => {
        res.data.forEach(item => {
          this.equipmentInfoOptions.push({
            value: item.id,
            label: item.name
          })
        })
      })
    },
    refresh() {
      this.pageData.pageNum = 1
      this.getList()
    },
    add() {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {}// props
        },
        area: ['1320px', '720px'],
        title: '新增设备信息', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    edit(row) {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            id: row[this.mainId]
          }// props
        },
        area: ['1320px', '720px'],
        title: '编辑设备信息', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    showDetail(row) {
      getInfo(row[this.mainId]).then(res => {
        this.$layer.iframe({// 弹框
          content: {
            content: ShowDetailOld, // 传递的组件对象
            parent: this, // 当前的vue对象
            data: {
              showData: res.data,
              showKey: this.showKey
            }// props
          },
          area: ['1320px', '720px'],
          title: '查看设备信息', // 标题
          shadeClose: false // 点击遮罩是否关闭
        })
      })
    },
    deleteOne(row) {
      const _this = this
      this.$confirm('确定要删除吗', '删除确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消', cancelButtonClass: 'cancelConfirm',
        type: 'warning'
      }).then(function() {
        remove(row[_this.mainId]).then(res => {
          _this.$message({
            message: res.msg,
            type: 'success'
          })
          _this.getList()
        })
      }).catch(() => {})
    },
    // 当前页的删除接口
    deleteMethod(deleteIds) {
      return remove(deleteIds)
    },
    getPrintData(data) {
      return list(data)
    },
    importMethod(files) { // 导入接口
      importMethod(files).then(res => {
        this.$message({
          message: res.msg,
          type: 'success'
        })
        this.getList()
      })
    }
  }
}
</script>

<style lang="less" scoped>
.accessory {
  color: #387bfc
}
.icon_notAvailable {
  width: 100% !important;
  height: 100% !important;
}
</style>
